package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.system.domain.PFileInfo;
import com.ruoyi.system.domain.vo.POrderVo;
import com.ruoyi.system.domain.dto.SelectPOrderDto;
import com.ruoyi.system.mapper.PFileInfoMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.POrderMapper;
import com.ruoyi.system.domain.POrder;
import com.ruoyi.system.service.IPOrderService;

/**
 * 订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-28
 */
@Service
public class POrderServiceImpl implements IPOrderService 
{
    @Autowired
    private POrderMapper pOrderMapper;
    @Autowired
    private PFileInfoMapper pFileInfoMapper;

    /**
     * 查询订单
     * 
     * @param id 订单主键
     * @return 订单
     */
    @Override
    public POrderVo selectPOrderById(Long id)
    {
        POrderVo vo= new POrderVo();
        POrder pOrder = pOrderMapper.selectPOrderById(id);
        BeanUtils.copyProperties(pOrder,vo);
        PFileInfo con = new PFileInfo();
        con.setContactId(id);
        con.setContactTable("p_order");
        List<PFileInfo> pFileInfos = pFileInfoMapper.selectPFileInfoList(con);
        vo.setpFileInfoList(pFileInfos);
        return vo;

    }

    /**
     * 查询订单列表
     * 
     * @param pOrder 订单
     * @return 订单
     */
    @Override
    public List<POrderVo> selectPOrderList(SelectPOrderDto dto)
    {
        return pOrderMapper.selectPOrderVoList(dto);
    }

    /**
     * 新增订单
     * 
     * @param pOrder 订单
     * @return 结果
     */
    @Override
    public int insertPOrder(POrder pOrder)
    {
        pOrder.setCreateTime(DateUtils.getNowDate());
        return pOrderMapper.insertPOrder(pOrder);
    }

    /**
     * 修改订单
     * 
     * @param pOrder 订单
     * @return 结果
     */
    @Override
    public int updatePOrder(POrder pOrder)
    {
        pOrder.setUpdateTime(DateUtils.getNowDate());
        return pOrderMapper.updatePOrder(pOrder);
    }

    /**
     * 批量删除订单
     * 
     * @param ids 需要删除的订单主键
     * @return 结果
     */
    @Override
    public int deletePOrderByIds(Long[] ids)
    {
        return pOrderMapper.deletePOrderByIds(ids);
    }

    /**
     * 删除订单信息
     * 
     * @param id 订单主键
     * @return 结果
     */
    @Override
    public int deletePOrderById(Long id)
    {
        return pOrderMapper.deletePOrderById(id);
    }
}
